package com.cgt.xiaotao.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cgt.xiaotao.user.domain.po.City;
import com.cgt.xiaotao.user.mapper.CityMapper;
import com.cgt.xiaotao.user.service.ICityService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class CityServiceImpl extends ServiceImpl<CityMapper, City> implements ICityService {

    @Override
    public List<City> listProvinces() {
        return this.list(new LambdaQueryWrapper<City>().eq(City::getLevelType, 1));
    }

    @Override
    public List<City> listCitiesByProvinceId(Integer provinceId) {
        return this.list(new LambdaQueryWrapper<City>()
                .eq(City::getParentId, provinceId)
                .eq(City::getLevelType, 2));
    }

    @Override
    public List<City> listDistrictsByCityId(Integer cityId) {
        return this.list(new LambdaQueryWrapper<City>()
                .eq(City::getParentId, cityId)
                .eq(City::getLevelType, 3));
    }
}
